<template>
	<view class="index">
		<!-- tabbar -->
		<block-bar :title="'首页'"></block-bar>
		<!-- 轮播图 -->
		<block-swipers :data="blockData.swipers"></block-swipers>
		<!-- 消息通知 -->
		<block-notice :data="blockData.notices"></block-notice>
		<!-- 菜单 -->
		<block-menu :width="20" :data="blockData.menus"></block-menu>
		<!-- 图片 -->
		<block-img :data="blockData.exhibition"></block-img>
		<!-- 榜单推荐 -->
		<block-rewords :data="data"></block-rewords>
		<!-- 淘宝客商品 -->
		<block-coupon-goods ref="loadMore" :isFixed="isFixed"></block-coupon-goods>
		<!-- #ifdef H5 -->
		<block-down-add></block-down-add>
		<!-- #endif -->
	</view>
</template>

<script>
	import BlockBar from '@/components/BlockBar/BlockBar.vue'
	import BlockSwipers from '@/components/BlockSwipers/BlockSwipers.vue'
	import BlockNotice from '@/components/BlockNotice/BlockNotice.vue'
	import BlockMenu from '@/components/BlockMenu/BlockMenu.vue'
	import BlockImg from '@/components/BlockImg/BlockImg.vue'
	import BlockRewords from '@/components/BlockRewords/BlockRewords.vue'
	import BlockCouponGoods from '@/components/BlockCouponGoods/BlockCouponGoods.vue'
	import BlockDownAdd from '@/components/BlockDownAdd/BlockDownAdd.vue'
	import {
		banner,
		recommendNews,
		menus,
		advertisement
	} from '@/api/index.js'
	import {
		rewardAll
	} from '@/api/reward.js'
	export default {
		components: {
			BlockBar,
			BlockSwipers,
			BlockNotice,
			BlockMenu,
			BlockImg,
			BlockRewords,
			BlockCouponGoods,
			BlockDownAdd
		},
		data() {
			return {
				blockData: {
					swipers: [],
					notices: [],
					menus: [],
					exhibition: {}
				},
				data:[],
				isFixed:false
			}
		},
		onLoad() {
			banner().then(res => {
				this.blockData.swipers = res.data
			})
			recommendNews().then(res => {
				this.blockData.notices = res.data
			})
			menus().then(res => {
				this.blockData.menus = res.data
			})
			advertisement({source:'index'}).then(res => {
				this.blockData.exhibition = res.data.length>0 ? res.data[0] : {};
			})
		},
		onShow() {
			this.getPushData();
		},
		//下拉刷新
		onPullDownRefresh() {
			this.getPushData();
		},
		//上拉加载
		onReachBottom(){
			this.$refs.loadMore.getData()
		},
		methods: {
			async getPushData(){
				let res = await rewardAll({page:1,size:10,recommend:1});
				if(res.code === 1){
					uni.stopPullDownRefresh();
					this.data = res.data;
				}
			}
		},
	}
</script>
<style lang="less" scoped src="./index.less"></style>
